import { fileURLToPath, URL } from 'node:url'
import { resolve, dirname } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

const __dirname = dirname(fileURLToPath(import.meta.url))

// https://vite.dev/config/
export default defineConfig({
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern-compiler',
                silenceDeprecations: ['legacy-js-api'],
                additionalData: `@use "/src/styles/vars.scss" as *;`,
            }
        }
    },
    publicDir: 'empty',
    plugins: [
        vue(),
        vueDevTools(),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    build: {
        outDir: 'dist/es',
        lib: {
            entry: resolve(__dirname, 'src/bundle.js'),
            name: 'LeeUi',
            fileName: "lee-ui",
            formats: ['es']
        },
        rollupOptions: {
            // 不需要打包
            external: ['vue', '@fortawesome/fontawesome-svg-core', '@fortawesome/free-solid-svg-icons', '@fortawesome/vue-fontawesome', '@popperjs/core', 'lodash-es'],
        }
    }
})
